//
//  CheckViewController.m
//  跨界收
//
//  Created by Allen on 2018/10/31.
//  Copyright © 2018年 gztx. All rights reserved.
//

#import "CheckViewController.h"
#import "checkItem.h"
#import "LYSDatePickerController.h"

@interface CheckViewController ()<LYSDatePickerSelectDelegate>

@property (weak, nonatomic) IBOutlet UILabel *endTimeLabel;
@property (weak, nonatomic) IBOutlet UILabel *startTimeLabel;
@property (weak, nonatomic) IBOutlet UIView *startView;
@property (weak, nonatomic) IBOutlet UIView *endView;
@property (nonatomic, strong) checkItem *itemView;
@property (weak, nonatomic) IBOutlet UIView *headerView;
@property (nonatomic, strong) NSString *startDateTimeSting;
@property (nonatomic, strong) NSString *selectStartDateString;
@property (nonatomic, strong) NSString *selectEndDateString;
@end

@implementation CheckViewController
- (void)initCheckItemView
{
 
    self.itemView = [[checkItem alloc] initWithFrame:CGRectMake(0, self.headerView.height+10, SCREEN_WIDTH, 198)];
    WeakSelf;
    self.itemView.clickBlock = ^(UIButton * _Nonnull sender) {
        NSLog(@"%d",sender.tag);
        
    };
    [self.view addSubview:self.itemView];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"筛选";
    [self initCheckItemView];
    [self initDate];
    
    // Do any additional setup after loading the view from its nib.
}
- (void)initDate
{
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap1:)];
    [self.startView addGestureRecognizer:tap1];
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap1:)];
    [self.endView addGestureRecognizer:tap2];
    NSDateFormatter *format=[[NSDateFormatter alloc] init];
    [format setDateFormat:@"yyyy-MM-day HH:mm:ss"];
    NSDateFormatter *dateFormat1 = [[NSDateFormatter alloc] init];
    [dateFormat1 setDateFormat:@"yyyy年MM月dd日 HH:mm:ss"];
    NSString *currentDate = [dateFormat1 stringFromDate:[NSDate date]];
    self.startTimeLabel.text = currentDate;
    self.endTimeLabel.text = currentDate;
}
- (void)initTipsView
{
    
}
////获取月份的最后一天
//- (NSString *)getMonthLastDay
//{
//     NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
//     NSRange range = [calendar rangeOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitMonth forDate:[NSDate date]];
//     NSUInteger numberOfDaysInMonth = range.length;
//    NSString *lastDay = [NSString stringWithFormat:@"%d",numberOfDaysInMonth];
//    return lastDay;
//}
//
//- (NSString *)getMonthBeginAndEndWith:(NSString *)dateStr{
//
//    NSDateFormatter *format=[[NSDateFormatter alloc] init];
//    [format setDateFormat:@"yyyy-MM--day"];
//    NSDate *newDate=[format dateFromString:dateStr];
//    double interval = 0;
//    NSDate *beginDate = nil;
//    NSDate *endDate = nil;
//    NSCalendar *calendar = [NSCalendar currentCalendar];
//
//    [calendar setFirstWeekday:2];//设定周一为周首日
//    BOOL ok = [calendar rangeOfUnit:NSMonthCalendarUnit startDate:&beginDate interval:&interval forDate:newDate];
//    //分别修改为 NSDayCalendarUnit NSWeekCalendarUnit NSYearCalendarUnit
//    if (ok) {
//        endDate = [beginDate dateByAddingTimeInterval:interval-1];
//    }else {
//        return @"";
//    }
//    NSDateFormatter *myDateFormatter = [[NSDateFormatter alloc] init];
//    [myDateFormatter setDateFormat:@"YYYY.MM.dd"];
//    NSString *beginString = [myDateFormatter stringFromDate:beginDate];
//    NSString *endString = [myDateFormatter stringFromDate:endDate];
//    NSString *s = [NSString stringWithFormat:@"%@-%@",beginString,endString];
//    return s;
//}

-(void)showView:(NSUInteger)tag
{
    WeakSelf;
    LYSDatePickerController *datePicker = [[LYSDatePickerController alloc] init];
    datePicker.headerView.backgroundColor = [UIColor colorWithRed:84/255.0 green:150/255.0 blue:242/255.0 alpha:1];
    datePicker.indicatorHeight = 1;
    datePicker.delegate = self;
    datePicker.headerView.centerItem.textColor = [UIColor whiteColor];
    datePicker.headerView.leftItem.textColor = [UIColor whiteColor];
    datePicker.headerView.rightItem.textColor = [UIColor whiteColor];
    datePicker.pickHeaderHeight = 40;
    datePicker.pickType = LYSDatePickerTypeDayAndTime;
    datePicker.minuteLoop = YES;
    datePicker.headerView.showTimeLabel = YES;
    datePicker.weakDayType = LYSDatePickerWeakDayTypeUSShort;
    datePicker.showWeakDay = YES;
    [datePicker setDidSelectDatePicker:^(NSDate *date) {
        NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
        [dateFormat setDateFormat:@"yyyy年MM月dd日 HH:mm:ss"];
        NSString *currentDate = [dateFormat stringFromDate:date];
        NSLog(@"%@",currentDate);
        if (tag == 1) {
            weakSelf.startTimeLabel.text = currentDate;
        }else{
            weakSelf.endTimeLabel.text = currentDate;
        }
        
    }];
    [datePicker showDatePickerWithController:self];
}


- (void)tap1:(UITapGestureRecognizer *)tap
{
    if ([tap.view isKindOfClass:[UIView class]]) {
        if (tap.view.tag == 1) {
            [self showView:tap.view.tag];
        }else if(tap.view.tag == 2){
            [self showView:tap.view.tag];
        }
        
    }
    
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
